package com.ruoyi.web.controller.modules;

import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.sdstc.modules.dto.AdjustDto;
import com.sdstc.modules.eneity.PlanEntity;
import com.sdstc.modules.service.PlanService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/**
 * @author ：wk
 * @date ：Created in 2022/11/2 15:35
 */
@RestController
@RequestMapping("/plan")
public class PlanController extends BaseController {

    @Autowired
    private PlanService planService;

    @PostMapping()
    public AjaxResult savePlan(@RequestBody PlanEntity planEntity){
        return AjaxResult.success(planService.savePlan(planEntity));
    }

    @PutMapping("/{id}")
    public AjaxResult updatePlan(@PathVariable String id, @RequestBody PlanEntity planEntity){
        return AjaxResult.success(planService.updatePlan(planEntity));
    }

    @DeleteMapping("/{id}")
    public AjaxResult deletePlanById(@PathVariable String id){
        planService.deletePlanById(id);
        return AjaxResult.success();
    }

    @GetMapping("/list")
    public TableDataInfo getPersonPage(PlanEntity plan){
        startPage();
        return getDataTable(planService.getPlanPage(plan));
    }

    @GetMapping("/getSnowFlakeId")
    public AjaxResult getSnowFlakeId(){
        return AjaxResult.success(planService.getSnowFlakeId());
    }

    @PostMapping("/tempSaveChange")
    public AjaxResult saveOrganPersonChange(@RequestBody AdjustDto adjustDto){
        return AjaxResult.success(planService.saveOrganPersonChange(adjustDto));
    }

    @PostMapping("/effectPlan/{planId}")
    public AjaxResult effectPlan(@PathVariable String planId){
        planService.effectPlan(planId);
        return AjaxResult.success();
    }

    @DeleteMapping("/reset/{tempVersionId}")
    public AjaxResult resetTempPlan(@PathVariable String tempVersionId){
        planService.resetTempPlan(tempVersionId);
        return AjaxResult.success();
    }

    @GetMapping("/getNewTempId")
    public AjaxResult getNewTempId(String planId){
        return AjaxResult.success(planService.getNewTempId(planId));
    }

    @RequestMapping(value = "/generationFile", method = RequestMethod.POST)
    public AjaxResult generationFile(@RequestParam("file") MultipartFile file){
        planService.saveGenerationFile(file);
        return AjaxResult.success();
    }

    @GetMapping("/queryEffectFile")
    public AjaxResult queryEffectFile(String planId){
        return AjaxResult.success(planService.queryEffectFile(planId));
    }
}
